// pages/catalog/catalog.js
//目前不知道服务器以及数据库完成度，一下数据均采用自定义静态数据

Page({
 
    /**
     * 页面的初始数据
     */
    data: {
      h1: (750 / wx.getSystemInfoSync().windowWidth) * wx.getSystemInfoSync().windowHeight - 1,
      classfiySelect: "",
      leftText: [{
          id: "01",
          text1: "茶点果干",
        },
        {
          id: "02",
          text1: "新鲜水果",
        },
        {
          id: "03",
          text1: "滋补品",
        },
        {
          id: "04",
          text1: "果酒",
        },
        {
          id: "05",
          text1: "水果蒸馏酒",
        },
        
   
      ],
      //sum为库存
      rightData: [{
          id: "01",
          title: "茶点果干",
          frist: [{
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
             
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
              id: 2,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
          ],
        },
        {
          id: "02",
          title: "新鲜水果",
          frist: [{
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
          ],
        },
        {
          id: "03",
          title: "滋补品",
          frist: [{
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
          ],
        },
        {
          id: "04",
          title: "果酒",
          frist: [{
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
          ],
        },
        {
          id: "05",
          title: "水果蒸馏酒",
          frist: [{
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
            {
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },{
              url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b1ebbd3c-ca49-405b-957b-effe60782276/c8c4e05e-42d4-4a22-b111-85765d4e22e2.jpg",
              text: "追源杨梅干",
              money: 200,
              sum: 20,
            },
          ],
        },
      ]
    },
   
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
      let shareid = options.shareid;

      if (shareid){
          wx.setStorageSync('shareid', shareid);
      }
      this.setData({
        classfiySelect: this.data.leftText[0].id,
      })
    },
   
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {
   
    },
   
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
      let index = wx.getStorageSync('catalog_index');
      let lefttext = this.data.leftText;
      if (index){
        this.setData({
          rigId:lefttext[index].id
        })
        wx.removeStorageSync('catalog_index');
      }else {
        this.setData({
          rigId:lefttext[0].id
        })
      }
    },
   
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {
   
    },
   
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {
   
    },
   
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
   
    },
   
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
   
    },
   
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
      return {
        title:'sharetest',
        path:'/pages/index/index?share=' + '54185418'
    }
    },
    // 高度适应
   

    //滚动触发
    scroll: function(e) {
      var scrollTop = e.detail.scrollTop,
        h = 0,
        classfiySelect;
      var that = this;
      that.data.leftText.forEach(function(clssfiy, i) {
        var _h =26 + that.length(clssfiy['id'])*102;
        if (scrollTop >= h){
          classfiySelect = clssfiy['id'];
        }
        h +=_h;
        // console.log(wx.getSystemInfoSync().windowHeight)
        console.log(scrollTop);
      })
      that.setData({
        classfiySelect: classfiySelect,
      })
    },
    //求每一栏高度
    length: function(e) {
      var that = this;
      var rightData = that.data.rightData;
      for (var i = 0; i < rightData.length; i++) {
        if(rightData[i]['id'] ==e){
          return rightData[i]['frist'].length;
   
        }
      }
    },
    //点击左边事件
    left_list: function(e) {
      var that = this;
      var l_id = e.currentTarget.dataset.id;
      that.setData({
        rigId: l_id,
      })
    },
    //跳转详情界面
    particulars:function(e){
        console.log(e);
        if (!wx.getStorageSync('rightData')){
          wx.setStorageSync('rightData', this.data.rightData);
        }
       
        wx.navigateTo({
          url: '/pages/product/product?index=' + e.currentTarget.dataset.index,
        })
    }
  })